package com.da.lon.wang.xlg.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.da.lon.wang.xlg.MyApplication;
import com.da.lon.wang.xlg.R;
import com.da.lon.wang.xlg.bean.ResultBean;
import com.da.lon.wang.xlg.constants.PreferencesConfig;
import com.da.lon.wang.xlg.constants.XLGConstants;
import com.da.lon.wang.xlg.http.HttpLoader;
import com.da.lon.wang.xlg.http.HttpLoader.OnWebLoadListenerReplay;
import com.da.lon.wang.xlg.imgupload.ChooseImageAvtivity;
import com.da.lon.wang.xlg.imgupload.ImageInfo;
import com.da.lon.wang.xlg.util.JavaScriptExit;
import com.da.lon.wang.xlg.util.LogUtils;
import com.da.lon.wang.xlg.util.MyBitmapFactory;
import com.da.lon.wang.xlg.util.PreferenceUtils;
import com.da.lon.wang.xlg.util.Utils;
import com.da.lon.wang.xlg.util.WebViewUtil;
import com.da.lon.wang.xlg.util.WebViewUtil.OnLoading;
import com.da.lon.wang.xlg.util.XLGDataUtils;
import com.umeng.analytics.MobclickAgent;

import net.tsz.afinal.http.AjaxParams;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;

public class WebViewActivity extends BaseActivity implements OnClickListener {

    private WebView webView;
    private final BroadcastReceiver replaySuccess = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String content = intent.getStringExtra("content");
            String type = intent.getStringExtra("type");
            if (type.equals(ChooseImageAvtivity.TYPE_REPLAY)) {
                webView.loadUrl("javascript:comment_show('" + content + "')");
            } else if (type.equals(ChooseImageAvtivity.TYPE_TOPIC)) {
                webView.loadUrl("javascript:topic_show('" + content + "')");
            } else if (type.equals(ChooseImageAvtivity.TYPE_MUSIC)) {
                webView.loadUrl("javascript:addscenc('" + content + "')");
            } else if (type.equals(ChooseImageAvtivity.TYPE_MODIFY_PHOTO)) {
                webView.loadUrl("javascript:head_show('" + content + "')");
            } else if (type.equals(ChooseImageAvtivity.TYPE_COMMENT_ORDER)) {
                webView.loadUrl("javascript:evalu_show('" + content + "')");
            } else if (type.equals(ChooseImageAvtivity.TYPE_SELL_MESSAGE)) {
                webView.loadUrl("javascript:tuikuan_show('" + content + "')");
            } else if (type.equals(ChooseImageAvtivity.TYPE_SUGGEST_MESSAGE)) {
                // javaScriptExit.clickOnAndroid(1, content);
                webView.loadUrl("javascript:yijian_show('" + content + "')");
            } else if (type.equals(ChooseImageAvtivity.TYPE_ORDER_PICTURE)) {
                webView.loadUrl("javascript:orderdeliveryimg('" + content
                        + "')");
            } else if (type.equals(ChooseImageAvtivity.TYPE_CUSTOMER_UPLOAD)) {
                webView.loadUrl("javascript:"
                        + WebViewUtil.customer_javascriptfunction + "('"
                        + content + "')");
            }

        }
    };
    private WebViewUtil webViewUtil;
    private final BroadcastReceiver registSuccess = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            webViewUtil.loadUrl();
        }
    };
    private final BroadcastReceiver wxPaySuccess = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String errCode = intent.getStringExtra("errCode");
            if (errCode.equals("0")) {
                Toast.makeText(WebViewActivity.this, "支付成功", Toast.LENGTH_LONG)
                        .show();
                webViewUtil.loadUrl(Utils
                        .constructUrl(WebViewUtil.wx_back_success_url));
            } else if (errCode.equals("-1")) {
                Toast.makeText(WebViewActivity.this, "支付失败", Toast.LENGTH_LONG)
                        .show();
                webViewUtil.loadUrl(Utils
                        .constructUrl(WebViewUtil.wx_back_success_url));
            } else if (errCode.equals("-2")) {
                Toast.makeText(WebViewActivity.this, "支付取消", Toast.LENGTH_LONG)
                        .show();
            }
        }
    };
    private ImageButton backButton;
    private ImageButton rightButton;
    private TextView titleTextView;
    Handler titleHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            titleTextView.setText(msg.obj.toString());
        }
    };
    private int flag;
    private String url;
    private String url_ad;
    private String merger_sn;
    private String orders_id;
    private String trade_number;
    private String title;
    private long firstTime = 0;
    private String sattr;
    private LinearLayout webview_ll;
    private JavaScriptExit javaScriptExit;

    public static String getWebHtml(String path) {
        String result = "";
        try {
            HttpURLConnection conn = (HttpURLConnection) new URL(path)
                    .openConnection();
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    conn.getInputStream()));
            String temp = "";
            while ((temp = reader.readLine()) != null) {
                result += temp;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
        MyApplication.clearActivityList();
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.ouka_webview);
        backButton = (ImageButton) findViewById(R.id.ouka_back);
        webView = (WebView) findViewById(R.id.ouka_webview);
        backButton.setOnClickListener(this);

        rightButton = (ImageButton) findViewById(R.id.ouka_party_right);
        rightButton.setVisibility(View.GONE);
        rightButton.setOnClickListener(this);

        titleTextView = (TextView) findViewById(R.id.title);
        javaScriptExit = new JavaScriptExit(webView);
        registerReplaySuccessReceiver();
        registRegistSuccessReceiver();
        registWxPaySuccessReceiver();
        try {
            init();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void init() throws Exception {
        webViewUtil = new WebViewUtil(this);
        Bundle bundle = this.getIntent().getExtras();
        if (null == bundle) {
            return;
        }
        url = bundle.getString("url");
        url_ad = bundle.getString("url_ad");

        merger_sn = bundle.getString("merger_sn");
        orders_id = bundle.getString("orders_id");
        trade_number = bundle.getString("trade_number");
        flag = bundle.getInt("flag");
        sattr = bundle.getString("sattr");
        switch (flag) {

            case 001:

                if (url.indexOf("cart-choicepay") != -1) {
                    backButton.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            String urlPay = XLGConstants.WEB_URL
                                    + "Member-orders.html";
                            webViewUtil.setWebView(Utils.constructUrl(urlPay),
                                    javaScriptExit, webView, 0);
                            webViewUtil.setOnloadingListener(new OnLoading() {

                                @Override
                                public void onStart(String url) {
                                    showDialog();
                                }

                                @Override
                                public void onGetLocation(String url) {

                                }

                                @Override
                                public void onError() {
                                    dismissDialog();
                                }

                                @Override
                                public void onComplete(String url) {
                                    dismissDialog();
                                }
                            });
                        }
                    });
                }
                webViewUtil.setWebView(Utils.constructUrl(url), javaScriptExit,
                        webView, 0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {

                    }

                    @Override
                    public void onError() {
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        dismissDialog();
                        setTitle(Utils.constructUrl(url));
                    }
                });

                break;

            case 002:
                if (url.indexOf("type=active") != -1
                        || url.indexOf("type-active") != -1) {
                    rightButton.setVisibility(View.VISIBLE);
                    // setTitle(url);
                }

                webViewUtil.setWebView(Utils.constructUrl(url), javaScriptExit,
                        webView, 0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {

                    }

                    @Override
                    public void onError() {
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        setTitle(url);
                        dismissDialog();
                    }
                });

                break;

            case 100:
                webViewUtil.setWebView(
                        Utils.constructUrl(XLGConstants.WEB_URL
                                + "Member-orders.html?"), javaScriptExit, webView,
                        0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        // TODO Auto-generated method stub
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }
                });
                break;
            case 200:
                webViewUtil.setWebView(
                        Utils.constructUrl(XLGConstants.WEB_URL
                                + "Member-ordersaddress.html?"), javaScriptExit,
                        webView, 0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        // TODO Auto-generated method stub
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }
                });
                break;
            case 300:
                webViewUtil.setWebView(
                        Utils.constructUrl(XLGConstants.WEB_URL
                                + "Member-myanquan.html?"), javaScriptExit,
                        webView, 0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {

                    }

                    @Override
                    public void onError() {
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        dismissDialog();
                    }
                });
                break;
            case 400:
                webViewUtil.setWebView(
                        Utils.constructUrl(XLGConstants.WEB_URL
                                + "Member-orders.html?"), javaScriptExit, webView,
                        0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {

                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }
                });
                break;
            case 500:
                webViewUtil.setWebView(
                        Utils.constructUrl(XLGConstants.WEB_URL
                                + "Member-myyijian.html?"), javaScriptExit,
                        webView, 0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        // TODO Auto-generated method stub
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }
                });
                break;
            case 600:
                webViewUtil.setWebView(
                        Utils.constructUrl(XLGConstants.WEB_URL
                                + "Member-setinfo.html?"), javaScriptExit, webView,
                        0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        // TODO Auto-generated method stub
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }
                });
                break;
            case 700:
                webViewUtil.setWebView(
                        Utils.constructUrl(XLGConstants.WEB_URL
                                + "Member-myaccount.html?"), javaScriptExit,
                        webView, 0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        // TODO Auto-generated method stub
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }
                });
                break;
            case 800:
                webViewUtil
                        .setWebView(
                                Utils.constructUrl(XLGConstants.WEB_URL
                                        + "Wallet-index.html?"), javaScriptExit,
                                webView, 0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        // TODO Auto-generated method stub
                        showDialog();
                        LogUtils.v("点击钱包进来了！---------------------");
                    }

                    @Override
                    public void onGetLocation(String url) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        // TODO Auto-generated method stub
                        dismissDialog();
                        setTitle(url);
                    }
                });
                break;

            case 900:
                webViewUtil.setWebView(Utils.constructUrl(url_ad), javaScriptExit,
                        webView, 0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        // TODO Auto-generated method stub
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }
                });
                break;

            case 1000:
                webViewUtil.setWebView(Utils.constructUrl(url), javaScriptExit,
                        webView, 0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        // TODO Auto-generated method stub
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }
                });
                break;

            case 1100:
                webViewUtil.setWebView(Utils.constructUrl(url), javaScriptExit,
                        webView, 0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        // TODO Auto-generated method stub
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }
                });
                break;

            case 1200:
                webViewUtil.setWebView(
                        Utils.constructUrl(XLGConstants.WEB_URL + "Public-Forgot"),
                        javaScriptExit, webView, 0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        // TODO Auto-generated method stub
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        // TODO Auto-generated method stub
                        dismissDialog();
                        titleTextView.setText("找回密码");
                    }
                });
                break;

            case 1300:
                webViewUtil.setWebView(
                        Utils.constructUrl(XLGConstants.WEB_URL
                                + "Member-orderdetail-msn-" + merger_sn + ".html"),
                        javaScriptExit, webView, 0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        // TODO Auto-generated method stub
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }
                });
                break;

            case 1400:
                webViewUtil.setWebView(
                        Utils.constructUrl(XLGConstants.WEB_URL
                                + "Member-ordertracking-order_id-" + orders_id
                                + ".html"), javaScriptExit, webView, 0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        // TODO Auto-generated method stub
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }
                });
                break;

            case 1500:
                webViewUtil.setWebView(
                        Utils.constructUrl(XLGConstants.WEB_URL
                                + "merchant-senddelivery-order_id-" + orders_id
                                + "-trade_number-" + trade_number + ".html"),
                        javaScriptExit, webView, 0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        // TODO Auto-generated method stub
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }
                });
                break;

            case 1600:
                webViewUtil.setWebView(
                        Utils.constructUrl(XLGConstants.WEB_URL
                                + "merchant-senddelivery-order_id-" + orders_id
                                + ".html"), javaScriptExit, webView, 0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        // TODO Auto-generated method stub
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }
                });
                break;

            case 1700:
                webViewUtil
                        .setWebView(
                                Utils.constructUrl(XLGConstants.WEB_URL
                                        + "Message-index.html"), javaScriptExit,
                                webView, 0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        // TODO Auto-generated method stub
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }
                });
                break;

            case 1800:
                // setTitle(constructUrl(url));
                titleTextView.setText("选择支付方式");
                webViewUtil.setWebView(Utils.constructUrl(url), javaScriptExit,
                        webView, 0);
                webViewUtil.setOnloadingListener(new OnLoading() {

                    @Override
                    public void onStart(String url) {
                        // TODO Auto-generated method stub
                        showDialog();
                    }

                    @Override
                    public void onGetLocation(String url) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }

                    @Override
                    public void onComplete(String url) {
                        // TODO Auto-generated method stub
                        dismissDialog();
                    }
                });
                break;

            default:
                break;
        }
    }

    private void setTitle(final String url) {
        try {
            new Thread() {
                @Override
                public void run() {
                    String html = getWebHtml(url).replace(" ", "");
                    if (html.indexOf("htitle") != -1) {
                        String temp = html.substring(html.indexOf("htitle"),
                                html.length());
                        title = temp.substring(temp.indexOf(">") + 1,
                                temp.indexOf("<"));
                        Message msg = new Message();
                        msg.obj = title;
                        titleHandler.sendMessage(msg);
                    } else if (html.indexOf("new-header") != -1) {
                        String temp = html.substring(
                                html.indexOf("new-header"), html.length());
                        if (temp.contains("tb-wz")) {
                            String temp1 = temp.substring(
                                    temp.indexOf("tb-wz"), temp.length());
                            title = temp1.substring(temp1.indexOf(">") + 1,
                                    temp1.indexOf("<"));
                        } else if (temp.contains("i-h-x")) {
                            String temp1 = temp.substring(
                                    temp.indexOf("i-h-x"), temp.length());
                            title = temp1.substring(temp1.indexOf(">") + 1,
                                    temp1.indexOf("<"));
                        } else {
                            if (temp.indexOf("<h2>") != -1) {
                                title = temp.substring(
                                        temp.indexOf("<h2>") + 4,
                                        temp.indexOf("</h2>"));
                            }
                            // else if(temp.indexOf("<h2 >") != -1){
                            // title = temp.substring(temp.indexOf("<h2  >") +
                            // 4,
                            // temp.indexOf("</h2>"));
                            // }
                            else {
                                title = "";
                            }
                        }
                        Message msg = new Message();
                        msg.obj = title;
                        titleHandler.sendMessage(msg);
                    } else if (html.indexOf("head-tip") != -1) {
                        String temp = html.substring(html.indexOf("head-tip"),
                                html.length());
                        title = temp.substring(temp.indexOf(">") + 1,
                                temp.indexOf("<"));
                        Message msg = new Message();
                        msg.obj = title;
                        titleHandler.sendMessage(msg);
                    }
                }

                ;
            }.start();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void onDestroy() {

        unregisterReplaySuccessReceiver();
        unregistRegistSuccessReceiver();
        unregistWxPaySuccessReceiver();
        webView.removeAllViews();
        webView.destroy();
        super.onDestroy();
    }

    private void registerReplaySuccessReceiver() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(XLGConstants.REPLAY_SUCCESS);
        registerReceiver(replaySuccess, intentFilter);
    }

    private void unregisterReplaySuccessReceiver() {
        unregisterReceiver(replaySuccess);
    }

    private void registRegistSuccessReceiver() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(XLGConstants.REGIST_SUCCESS);
        registerReceiver(registSuccess, intentFilter);
    }

    private void unregistRegistSuccessReceiver() {
        unregisterReceiver(registSuccess);
    }

    private void registWxPaySuccessReceiver() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(XLGConstants.WX_PAY_SUCCESS);
        registerReceiver(wxPaySuccess, intentFilter);
    }

    private void unregistWxPaySuccessReceiver() {
        unregisterReceiver(wxPaySuccess);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
            case R.id.ouka_back:
                // Intent intent = new
                // Intent(WebViewActivity.this,HomeActivity.class);
                // startActivity(intent);
                // finish();
                if (webView.canGoBack()) {
                    webView.goBack(); // goBack()表示返回webView的上一页面
                } else {
                    finish();
                }
                break;

            case R.id.ouka_party_right:

                try {
                    String pro_name = title;
                    String uri = url;
                    if (pro_name == null) {
                        pro_name = "";
                    }
                    if (uri == null) {
                        uri = "";
                    }
                    Utils.showShare(WebViewActivity.this, pro_name, null, uri, null);
                } catch (Exception e) {
                    Toast.makeText(this, "参数有误", Toast.LENGTH_SHORT).show();
                }

                break;

            default:
                break;
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        try {
            switch (requestCode) {
                case 2000:
                    if (resultCode == RESULT_OK) {
                        String photoPath = WebViewUtil.getPhotoPath();
                        if (!TextUtils.isEmpty(photoPath)) {
                            ImageInfo imageInfo = new ImageInfo();
                            imageInfo.path = photoPath;
                            MyApplication.getInstance().addImageInfo(imageInfo);
                            if (!WebViewUtil.isHaveChoose) {

                                if (MyApplication.isMyoption()) {
                                    // suggestMessage();
                                    Intent intent = new Intent(
                                            WebViewActivity.this,
                                            ChooseImageAvtivity.class);
                                    intent.putExtra("type", "replay");
                                    startActivity(intent);
                                } else {
                                    Intent intent = new Intent(
                                            WebViewActivity.this,
                                            ChooseImageAvtivity.class);
                                    intent.putExtra("type", "replay");
                                    startActivity(intent);
                                }
                            }

                        }
                    } else if (resultCode == RESULT_CANCELED) {

                    } else {

                        if (!WebViewUtil.isHaveChoose) {
                            if (MyApplication.isMyoption()) {
                                suggestMessage();
                            } else {
                                Intent intent = new Intent(WebViewActivity.this,
                                        ChooseImageAvtivity.class);
                                intent.putExtra("type", "replay");
                                startActivity(intent);
                            }
                        }
                    }
                    break;

                case 2001:
                    if (resultCode == RESULT_OK) {
                        String photoPath = WebViewUtil.getPhotoPath();
                        if (!TextUtils.isEmpty(photoPath)) {
                            ImageInfo imageInfo = new ImageInfo();
                            imageInfo.path = photoPath;
                            MyApplication.getInstance().addImageInfo(imageInfo);
                            if (!WebViewUtil.isHaveChoose) {

                                if (MyApplication.isMyoption()) {
                                    suggestMessage();
                                } else {
                                    Intent intent = new Intent(
                                            WebViewActivity.this,
                                            ChooseImageAvtivity.class);
                                    intent.putExtra("type", "replay");
                                    startActivity(intent);
                                }
                            }

                        }
                    } else {

                        if (!WebViewUtil.isHaveChoose) {
                            if (MyApplication.isMyoption()) {
                                if (MyApplication.getInstance().imageInfos != null
                                        && MyApplication.getInstance().imageInfos
                                        .size() != 0) {
                                    suggestMessage();
                                }
                            } else {
                                Intent intent = new Intent(WebViewActivity.this,
                                        ChooseImageAvtivity.class);
                                intent.putExtra("type", "replay");
                                startActivity(intent);
                            }
                        }
                    }
                    break;
                case 28:
                    javaScriptExit.clickOnAndroid(4, null);
                    break;
                default:
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    /**
     * 意见反馈
     */

    private void suggestMessage() {
        String url = XLGConstants.URL + "Login-yijian";
        HttpLoader<ResultBean> httpLoader = new HttpLoader<ResultBean>(this,
                url, ResultBean.class);
        AjaxParams params = new AjaxParams();
        try {
            List<ImageInfo> imageInfos = MyApplication.getInstance().imageInfos;
            for (int i = 0; imageInfos != null && i < imageInfos.size(); i++) {
                File saveMyBitmap = MyBitmapFactory.saveMyBitmap(
                        "compressImage" + i + ".jpg",
                        MyBitmapFactory.getMatrixImage(imageInfos.get(i).path));
                if (saveMyBitmap == null) {
                    continue;
                }
                params.put("file" + i, saveMyBitmap);
            }
            params.put(
                    "id",
                    PreferenceUtils.getInstance().getSettingStr(
                            PreferencesConfig.USER_ID, ""));
            params.put(
                    "user_key",
                    PreferenceUtils.getInstance().getSettingStr(
                            PreferencesConfig.USER_KEY, ""));
            params.put(
                    "token",
                    XLGDataUtils.encrypt2MD5("Login" + XLGConstants.SECRET
                            + "yijian"));
            params.put("device_type", "1");
            httpLoader
                    .setReplayManagerListener(new OnWebLoadListenerReplay<ResultBean>() {

                        @Override
                        public void OnStart() {
                            showDialog("上传中");
                        }

                        @Override
                        public void OnError(String error) {
                            dismissDialog();
                            Toast.makeText(WebViewActivity.this, "上传失败",
                                    Toast.LENGTH_SHORT).show();
                            MyApplication.setMyoption(false);

                        }

                        @Override
                        public void onSuccess(ResultBean t, String result) {
                            dismissDialog();
                            if (t != null) {
                                if (t.getCode().equals("000000")) {
                                    Toast.makeText(WebViewActivity.this,
                                            "上传成功", Toast.LENGTH_SHORT).show();
                                    javaScriptExit.clickOnAndroid(1, result);
                                    LogUtils.v("上传成功******************");
                                } else {
                                    Toast.makeText(WebViewActivity.this,
                                            t.getMessage(), Toast.LENGTH_SHORT)
                                            .show();
                                }
                                MyApplication.setMyoption(false);
                            }

                        }
                    });

            httpLoader.loadReplayData(params);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void finish() {
        Utils.clearCookies(this);
        super.finish();
    }
}
